package com.itheima.goods.controller;

import com.itheima.goods.pojo.Brand;
import com.itheima.goods.pojo.Category;
import com.itheima.goods.service.CategoryService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class CategoryController {


    @Autowired
    private CategoryService categoryService;

    //查询所有
    @GetMapping("/category")
    public Result findAll() {
        Result<Category> result = categoryService.findAll();
        return result;
    }

    //添加类别
    @PostMapping("/category")
    public Result add(@RequestBody Category category) {
        Result result = categoryService.add(category);
        return result;
    }

    //分页查询
    @GetMapping("/category/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        Result<Category> result = categoryService.findPage(page, size);
        return result;
    }

    //条件分页查询
    @PostMapping("/category/search/{page}/{size}")
    public Result findPage1(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody Category category) {
        Result<Category> result = categoryService.TfindPage(page, size, category);
        return result;
    }

    //根据id；查询
    @GetMapping("/category/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        return categoryService.findById(id);
    }


    //修改brand数据
    @PutMapping("/category/{id}")
    public Result updateById(@PathVariable("id") Integer id, @RequestBody Category category) {
        return categoryService.updateById1(category, id);
    }

    //根据id删除
    @DeleteMapping("/category/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return categoryService.deleteById(id);
    }

}
